package cn.hanyx.coder.design.pattern.behavioral.state.demo01;

import java.util.concurrent.locks.StampedLock;

/**
 * MarioStateMachine
 * <p>
 * 状态机实现方式一：分支逻辑法
 * <p>
 * 对于简单的状态机来说，这种实现方式最简单、最直接，是首选
 *
 * @author hanyx
 * @date 2020/06/08
 */
public class MarioStateMachine {
    private int score;
    private State currentState;

    public MarioStateMachine() {
        score = 0;
        currentState = State.SMALL;
    }

    /**
     * 碰到蘑菇
     */
    public void obtainMushRoom() {
        if (currentState.equals(State.SMALL)) {
            this.currentState = State.SUPER;
        }
        this.score += 100;
    }

    /**
     * 碰到斗篷
     */
    public void obtainCape() {
        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER) || currentState.equals(State.FIRE)) {
            this.currentState = State.CAPE;
        }
        this.score += 200;
    }

    /**
     * 获得火焰
     */
    public void obtainFireFlower() {
        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER) || currentState.equals(State.CAPE)) {
            this.currentState = State.FIRE;
        }
        this.score += 200;
    }

    /**
     * 碰到怪物
     */
    public void meetMonster() {
        if (!currentState.equals(State.SMALL)) {
            this.currentState = State.SMALL;
        } else {
            this.currentState = State.DIE;
        }
        this.score -= 100;
    }

    public int getScore() {
        return score;
    }

    public State getCurrentState() {
        return currentState;
    }
}
